//package com.zhuyuan.getaway.config;
//
///**
// * @Author: 张琳凯
// * @Description: TODO
// * @DateTime: 2025/2/9 23:47
// **/
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.route.RouteLocator;
//import org.springframework.context.annotation.Primary;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Component
//@Primary
//public class GatewaySwaggerResourcesProvider implements SwaggerResourcesProvider {
//
//    @Autowired
//    private RouteLocator routeLocator;
//
//    @Override
//    public List<SwaggerResource> get() {
//        List<SwaggerResource> resources = new ArrayList<>();
//        routeLocator.getRoutes()
//                .filter(route -> route.getUri().getHost() != null)
//                .subscribe(route -> {
//                    String name = route.getId();
//                    String url = "/" + route.getId() + "/v3/api-docs"; // 微服务的 OpenAPI 路径
//                    resources.add(swaggerResource(name, url));
//                });
//        return resources;
//    }
//
//    private SwaggerResource swaggerResource(String name, String url) {
//        SwaggerResource resource = new SwaggerResource();
//        resource.setName(name);
//        resource.setUrl(url);
//        resource.setSwaggerVersion("3.0");
//        return resource;
//    }
//}